package com.haorui.lygyd.wxapi.utils;

import com.haorui.base.core.dto.AuthDto;
import com.haorui.base.core.utils.ApplicationContextUtil;
import com.haorui.base.core.utils.BeanUtil;
import com.haorui.lygyd.employeemanager.entity.MemberEntity;
import com.haorui.lygyd.employeemanager.service.MemberService;
import org.springframework.security.core.context.SecurityContextHolder;

import java.math.BigDecimal;

/**
 * @author 郭飞
 * @version 1.0
 * @project znsm
 * @package com.haorui.znsm.wxapi.utils
 * @createDate 2018/3/20 0020 22:01
 * @modfiyDate
 * @function
 */
public class MemberLoginUtil {
    public static MemberEntity getCurrentLoginMember(){
        if(SecurityContextHolder.getContext().getAuthentication()!=null){
            Object obje=SecurityContextHolder.getContext().getAuthentication().getDetails();
            if(obje instanceof AuthDto){
                AuthDto userDetails=(AuthDto) obje;
                MemberService memberService=(MemberService) ApplicationContextUtil.getContext().getBean("memberService");
                return memberService.findOne(userDetails.getId());
            }else {
                return null;
            }

        }else {
            return null;
        }
    }

    public static String getMemberId(){
        if(SecurityContextHolder.getContext().getAuthentication()!=null){
            Object obje=SecurityContextHolder.getContext().getAuthentication().getDetails();
            if(obje instanceof AuthDto){
                AuthDto userDetails=(AuthDto) obje;
                return userDetails.getId();
            }else {
                return null;
            }

        }else {
            return null;
        }
    }

}
